{include file="common/header" title="管理员增加"}
<div class="x-body">
    <form class="layui-form" lay-filter="formBox">
        <div class="layui-form-item">
            <label for="pid" class="layui-form-label">
                <span class="x-red">*</span>上级栏目
            </label>
            <div class="layui-input-inline">
                <select name="pid" id="pid" lay-verify="pid">
                    <option value="">请选择上级栏目</option>
                    {volist name="columnList" id="item"}
                    {eq name="item.pid" value="0"}
                    <option value="{$item.id}">{$item.name}</option>
                    {else /}
                    <option value="{$item.id}">{:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $item.level)}|---{$item.name}</option>
                    {/eq}
                    {/volist}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>不选择即为顶级栏目
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>栏目中文名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="name"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name_en" class="layui-form-label">
                <span class="x-red"></span>栏目英文名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name_en" name="name_en" lay-verify="name_en"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>要跟控制器名一致
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red"></span>描述
            </label>
            <div class="layui-input-inline">
                <textarea name="description"  placeholder="请输入描述" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red"></span>是否隐藏
            </label>
            <div class="layui-input-block">
                <style>
                    .layui-form-switch {
                        margin-top: 8px;
                    }
                </style>
                <input type="checkbox" name="status" value="1" lay-skin="switch" lay-text="显示|隐藏">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="sort" class="layui-form-label">
                <span class="x-red"></span>排序
            </label>
            <div class="layui-input-inline">
                <input type="number" id="sort" name="sort" required="" lay-verify="sort"
                        value="0" placeholder="默认排序为0" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <input type="hidden" name="id">
            <button class="layui-btn" lay-filter="save" lay-submit="">修改</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        form.val("formBox", {$data});

        //自定义验证规则
        form.verify({
            name: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '栏目名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '栏目名不能全为数字';
                }
                if (!value) {
                    return '栏目名不能为空';
                }
                if (value.length > 45) {
                    return '栏目名不得超过45个字符啊';
                }
            },
            name_en: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value) {
                    if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                        return '栏目英文名首尾不能出现下划线\'_\'';
                    }
                    if (!/^[a-zA-Z]+$/.test(value)) {
                        return '栏目英文名只能为英文';
                    }
                    if (!value) {
                        return '栏目英文名不能为空';
                    }
                    if (value.length > 45) {
                        return '栏目英文名不得超过45个字符啊';
                    }
                }
            }
        });

        //监听提交
        form.on('submit(save)', function (data) {
            //发异步，把数据提交给php
            $.post('{:url("save")}', {data: data.field}, function (reg) {
                switch (reg.code) {
                    case 0:
                        layer.msg(reg.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            // 可以对父窗口进行刷新
                            x_admin_father_reload();
                        });
                        break;
                    default:
                        layer.msg(reg.msg, {icon: 5});
                }

            }, 'json');
            return false;
        });


    });
</script>
</body>

</html>